﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;

namespace nERP.ViewModel.Bas.WarehouseVMs
{
    public partial class WarehouseListVM : BasePagedListVM<Warehouse_View, WarehouseSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Warehouse_View>> InitGridHeader()
        {
            return new List<GridColumn<Warehouse_View>>{
                
                this.MakeGridHeader(x => x.Warehouse_WarehouseCode).SetTitle(@Localizer["Page.仓库编码"].Value),
                this.MakeGridHeader(x => x.Warehouse_WarehouseName).SetTitle(@Localizer["Page.仓库名称"].Value),
                this.MakeGridHeader(x => x.Warehouse_Address).SetTitle(@Localizer["_Admin.Address"].Value),
                this.MakeGridHeader(x => x.Warehouse_StorageFee).SetTitle(@Localizer["Page.仓储费"].Value),
                this.MakeGridHeader(x => x.Warehouse_ChargePerson).SetTitle(@Localizer["Page.负责人"].Value),
                this.MakeGridHeader(x => x.Warehouse_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.Warehouse_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.Warehouse_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.Warehouse_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.Warehouse_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.Warehouse_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Warehouse_View> GetSearchQuery()
        {
            var query = DC.Set<Warehouse>()
                
                .CheckContain(Searcher.WarehouseCode, x=>x.WarehouseCode)
                .CheckContain(Searcher.WarehouseName, x=>x.WarehouseName)
                .CheckContain(Searcher.Address, x=>x.Address)
                .CheckEqual(Searcher.StorageFee, x=>x.StorageFee)
                .CheckEqual(Searcher.ChargePersonId, x=>x.ChargePersonId)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new Warehouse_View
                {
				    ID = x.ID,
                    
                    Warehouse_WarehouseCode = x.WarehouseCode,
                    Warehouse_WarehouseName = x.WarehouseName,
                    Warehouse_Address = x.Address,
                    Warehouse_StorageFee = x.StorageFee,
                    Warehouse_ChargePerson = DC.Set<FrameworkUser>().Where(z0 => z0.ITCode == x.ChargePersonId).Select(y => y.Name).FirstOrDefault(),
                    Warehouse_Remark = x.Remark,
                    Warehouse_CreateTime = x.CreateTime,
                    Warehouse_UpdateTime = x.UpdateTime,
                    Warehouse_CreateBy = x.CreateBy,
                    Warehouse_UpdateBy = x.UpdateBy,
                    Warehouse_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Warehouse_View: Warehouse
    {
        
        public string Warehouse_WarehouseCode { get; set; }
        public string Warehouse_WarehouseName { get; set; }
        public string Warehouse_Address { get; set; }
        public decimal? Warehouse_StorageFee { get; set; }
        public string Warehouse_ChargePerson { get; set; }
        public string Warehouse_Remark { get; set; }
        public DateTime? Warehouse_CreateTime { get; set; }
        public DateTime? Warehouse_UpdateTime { get; set; }
        public string Warehouse_CreateBy { get; set; }
        public string Warehouse_UpdateBy { get; set; }
        public bool Warehouse_IsValid { get; set; }

    }

}